export default function (hiprint, module, list) {
    let groups = list.map(item => {
        let children = item.children.map(child => {
            let obj = {
                tid: `${module}.${item.code}_${child.code}`,
                title: child.name,
                type: child.cfg_type,
                data: child.note_info,
            };
            if (child.cfg_type === 'table') {
                let columns = JSON.parse(child.columns_json);
                columns = columns.sort((a, b) => a._index - b._index);
                obj.options = {
                    field: child.code,
                    tableHeaderRepeat: 'page',
                    tableFooterRepeat: 'page',
                    fields: columns,
                };
                obj.columns = [
                    columns.map(col => {
                        return {
                            title: col.text,
                            field: col.field,
                            align: 'center',
                        };
                    })
                ];
            } else {
                let hideTitle = false;
                if (child.file === 1) {
                    hideTitle = true;
                }
                obj.options = {
                    fixedValue: child.file,
                    field: child.code,
                    testData: child.note_info,
                    hideTitle,
                };
            }
            return obj;
        });
        return new hiprint.PrintElementTypeGroup(item.name, children);
    });
    groups.push( new hiprint.PrintElementTypeGroup("基础", [
        {
            tid: "baseModule.text",
            title: "文本",
            type: "text"
        },
        {
            tid: "baseModule.image",
            title: "图片",
            type: "image"
        },
        {
            tid: "baseModule.longText",
            title: "长文本",
            type: "longText"
        },
        {
            tid: "baseModule.table",
            field: "table",
            title: "表格",
            type: "table",
            groupFields: [ "name" ],
            columns: [
                [
                    { title: '', align: 'center' },
                    { title: '', align: 'center' },
                    { title: '', align: 'center' },
                ],
            ],
            editable: true,
            columnDisplayEditable: true,//列显示是否能编辑
            columnDisplayIndexEditable: true,//列顺序显示是否能编辑
            columnTitleEditable: true,//列标题是否能编辑
            columnResizable: true, //列宽是否能调整
            columnAlignEditable: true,//列对齐是否调整
            isEnableEditField: true, //编辑字段
            isEnableContextMenu: true, //开启右键菜单 默认true
            isEnableInsertRow: true, //插入行
            isEnableDeleteRow: true, //删除行
            isEnableInsertColumn: true, //插入列
            isEnableDeleteColumn: true, //删除列
            isEnableMergeCell: true, //合并单元格
        },
        {
            tid: "baseModule.html",
            title: "html",
            formatter: function (data, options) {
                return '<div style="height:50pt;width:50pt;background:red;border-radius: 50%;"></div>';
            },
            type: "html"
        },
        {
            tid: "baseModule.customText",
            title: "自定义文本",
            customText: "自定义文本",
            custom: true,
            type: "text"
        },
    ]));
    groups.push( new hiprint.PrintElementTypeGroup("辅助", [
        {
            tid: "defaultModule.hline",
            title: "横线",
            type: "hline"
        },
        {
            tid: "defaultModule.vline",
            title: "竖线",
            type: "vline"
        },
        {
            tid: "defaultModule.rect",
            title: "矩形",
            type: "rect"
        },
        {
            tid: "defaultModule.oval",
            title: "椭圆",
            type: "oval"
        }
    ]));
    return options => {
        const addElementTypes = context => {
            context.removePrintElementTypes(module);
            context.addPrintElementTypes(module, groups);
        };
        return {
            addElementTypes: addElementTypes
        };
    };
};
